{extend name="platform/base" /}
{block name="resources"/}
<style>
.checkbox-inline {
	padding-left: 0px;
}
</style>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 修改导航 </header>
	<div class="panel-body">
		<form class="form-horizontal" method="get">
			<div class="form-group">
				<label class="col-sm-2 control-label">导航名称</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="nav_title" value="{$data['nav_title']}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">排序号</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="sort" value="{$data['sort']}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">链接地址</label>
				<div class="col-md-6">
					<label for="url_type1" style="margin-top: 5px;margin-left: 10px;">
       					 <input type="radio" value="0" name="url_type" id="url_type1"  {if condition="$data['nav_type'] eq 0"}checked{/if}/>
       					 商城模块
       			    </label>
       			    <label for="url_type2" style="margin-top: 5px;">
       			    	<input type="radio" value="1" name="url_type" id="url_type2" {if condition="$data['nav_type'] eq 1"}checked{/if}/>
       			                    自定义链接
       			    </label>
<!-- 					<input type="radio" class="form-control" id="nav_url" value=""> -->
				</div>
				<div class="col-md-6">
					<select name="" id="shopNavModel" style="margin-left: 200px;margin-top: 11px;width:178px;border-color:#d9d9d9;color:#999;height:30px;{if condition="$data['nav_type'] neq 0"}display: none;{/if}">
			          <option value="">请选择</option>
			          {notempty name="shopNavTemplate"}
			            {foreach name="shopNavTemplate" item="vo"}
			            <option value="{$vo.template_url}" {if condition="$data['nav_url'] eq $vo['template_url']"}selected{/if}>{$vo.template_name}</option>
			            {/foreach}
			          {/notempty}
			       </select>
			       <span style="margin-left: 200px;{if condition="$data['nav_type'] neq 1"}display: none;{/if}" id="nav_url">
			          <input  type="text"  value="{$data.nav_url}" name="nav_url" style="width:210px;height:30px;margin-top:11px;"/>
			          <span style="line-height: 28px;color: #999;">如：http://www.niushop.com.cn/</span>
			       </span>
				</div>
				
				
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
                 <label class="col-sm-2 control-label">所在位置</label>
                 <div class="col-sm-10">
                     <label class="checkbox-inline">
                         <input type="radio" name="type" id="type1" value="1" {if condition="$data['type'] eq 1"}checked{/if}> 头部 </label>
                     <label class="checkbox-inline">
                         <input type="radio" name="type" id="type2" value="2" {if condition="$data['type'] eq 2"}checked{/if}> 中部 </label>
                     <label class="checkbox-inline">
                         <input type="radio" name="type" id="type3" value="3" {if condition="$data['type'] eq 3"}checked{/if}> 底部 </label>
                 </div>
            </div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
                 <label class="col-sm-2 control-label">是否新窗口打开</label>
                 <div class="col-sm-10">
                     <label class="checkbox-inline">
                         <input type="radio" value="1" name="is_blank" id="is_blank1" {if condition="$data['is_blank'] eq 1"}checked=""{/if}/> 是 
                     </label>
                     <label class="checkbox-inline">
                         <input type="radio" value="0" name="is_blank" id="is_blank2" {if condition="$data['is_blank'] eq 0"}checked=""{/if} /> 否 
                     </label>
                 </div>
            </div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<input type="hidden" id="nav_id" value="{$data['nav_id']}">
					<a href="javascript:void(0);" onclick="updateShopNavigationAjax()" class="btn btn-primary">保存</a>
				</div>
			</div>
		</form>
	</div>
</section>
{/block} 
{block name="script"}
  <script type="text/javascript">
     function updateShopNavigationAjax(){
    	 var nav_id=$("#nav_id").val();
    	 var nav_title=$("#nav_title").val();
    	 var sort=$("#sort").val();
    	 var type=$("input[type='radio'][name='type']:checked").val();
    	 var url_type = $("input[name=url_type]:checked").val();
         if(url_type == 0){
             var nav_url=$("#shopNavModel").val();
             var template_name = $("#shopNavModel option:selected").text();
         }else if(url_type == 1){
             var nav_url=$("input[name=nav_url]").val();
             var template_name = '';
         }
   	   	if(nav_url == ''){
   	   		showMessage('error',"链接地址不能为空");
   		   	return false;	
   	   	}
   	   	var is_blank = $("input[name=is_blank]:checked").val();
    	$.ajax({
    		type:"post",
    	    url:"PLATFORM_MAIN/Config/updateShopNavigation",
    	    data:{
    	      'nav_id':nav_id,   
    	      'nav_title':nav_title,   
    	      'sort':sort,
    	      'nav_url':nav_url,
    	      'type':type,
              'nav_type' : url_type,
              'is_blank' : is_blank,
              'template_name' : template_name
    	    },
    	    async : true,
    	    success:function(data){
    	    	 if (data["code"] > 0) {
    						showMessage('success', data["message"], "PLATFORM_MAIN/Config/shopNavigationList");
    					}else{
    						showMessage('error', data["message"]);
    					} 
    	    } 
    	});
     }
     $("#url_type1").click(function(){
         $("#shopNavModel").show();
         $("#nav_url").hide();
        })
     $("#url_type2").click(function(){
      $("#shopNavModel").hide();
      $("#nav_url").show();
     })
  </script>
{/block}